home *** CD-ROM | disk | FTP | other *** search
/ Floppyshop 2 / Floppyshop - 2.zip / Floppyshop - 2.iso / art&graf.ix / art-0015 / flicker / drabrush.asm < prev    next >
Assembly Source File  |  1997-04-16  |  12KB  |  637 lines

  1.  
  2. ; :ts=10
  3.  
  4.     public _cscreen
  5.  
  6.     ; This file contains some interesting routines and a bunch of
  7.     ; boring ones.  The purpose of them all is to very quickly draw
  8.     ; a 16x16 brush onto the screen.  To avoid branches in the
  9.     ; inner loop based on color, I've resorted to the ever popular
  10.     ; on the ST expedient of coding one routine for each color.
  11.     ; Thus this file looks very big but it actually contains very
  12.     ; little.
  13.  
  14.     ; Also for speeds sake I have 16 copies of the active brush.
  15.     ; Each is shifted a pixel right of the one before.
  16.     ; The lower 4 bits of the x drawing position determine which
  17.     ; copy of the brush is used, and I don't shift at all during 
  18.     ; draw time, just when the "current" brush is changed.
  19.  
  20.     ; shift_brush - make shifted copy of brush .. ie 16x16x1 bitmap
  21.     ;    a0 = brush
  22.     ;    a1 = place to put shifted copy
  23.     ;    d0 = #to shift
  24. shift_brush 
  25.     move.l    #15,d2
  26. scurloop     move.w    (a0)+,d1
  27.     swap    d1
  28.     move.w    #0,d1
  29.     lsr.l    d0,d1
  30.     move.l    d1,(a1)+
  31.     dbra    d2,scurloop
  32.     rts
  33.  
  34.     ;preshift(brush)
  35.     ;    put 16 variously shifted copies of brush in preshifts
  36.     ;    buffer so don't have to shift during draw time...
  37.     public _preshift
  38. _preshift    move.l    #preshifts,a1    ; get destination for shifting
  39.     move.w    #0,d0            ; count up to 16 in d0
  40. psloop    move.l    4(sp),a0
  41.     bsr    shift_brush
  42.     addq.w    #1,d0
  43.     cmp.w    #16,d0
  44.     bne    psloop
  45.     rts
  46.  
  47.  
  48.  
  49.     ;draw_brush(brush, x, y, color)
  50.         ; draw unpre-shifted brush
  51.     public _draw_brush
  52. _draw_brush
  53.     ;    first go make an alligned copy of brush int shift_buf
  54.     move.l    4(sp),a0
  55.     move.w    8(sp),d0
  56.     and.w    #15,d0
  57.     move.l    #shift_buf,a1
  58.     bsr    shift_brush
  59.     ;    now have to re-arrange stack parameters, what a drag!
  60.     move.l    8(sp),4(sp)    ; move over x and y
  61.     move.w    12(sp),8(sp)    ; move over color
  62.     move.l    #shift_buf,a2
  63.     bra    draw_alligned_brush
  64.  
  65.  
  66.  
  67.     ;draw_shifted(x, y, color)
  68.         ; draw brush from pre-shifted array
  69.         ; only drag is that for draw_alligned_brush
  70.         ; rearranging stack frame ...
  71.     public _draw_shifted
  72. _draw_shifted
  73.     move.l    #preshifts,a2    ;get address of preshifts
  74.     move.w    4(sp),d0    ;get x coordinate
  75.     and.w    #15,d0    ;only interested in last 4 bits
  76.     lsl.w    #6,d0    ;64 bytes/preshifted copy
  77.     adda.w    d0,a2    ;now a0 points to brush properly shifted for x
  78.     ;    and fall through to draw_alligned_brush
  79.  
  80.  
  81.  
  82.     ;draw_alligned_brush(x, y, color)
  83.         ; draw pre-shifted brush
  84.         ; x,y,color arguments on stack,
  85.         ; brush pointer already in a2
  86. draw_alligned_brush
  87.     move.w    #15,d1    ;line count
  88. get_y
  89.     move.w    6(sp),d0    ; get y coordinate
  90.     bge    yposi    ; start clipping ... at least it's positive
  91.     cmp.w    #-16,d0    ; is it completely above screen?
  92.     bls    clipout
  93.     add.w    d0,d1    ; y negative a little, makes less than 16 lines...
  94.     move.w    d0,d2
  95.     asl.w    #2,d2    
  96.     suba.w    d2,a2    ; and we have to start in middle of source
  97.     move.w    #0,d0    ; and after clipping start at 0
  98.     bra    get_color    ; and go get y address
  99. yposi
  100.     cmp.w    #200,d0    ; totally below screen?
  101.     bge    clipout
  102.     move.w    d0,d2
  103.     sub.w    #200-16,d2  ; # of lines off bottom of screen in d2
  104.     bls    get_color    ; if negative or zero don't have to clip
  105.     sub.w    d2,d1    ; ready to draw a few less lines
  106. get_color    
  107.     move.w    8(sp),d2    ; get color parameter
  108.     lsl.w    #2,d2    ; convert to pointer value
  109. get_x
  110.     move.l    _cscreen,a0
  111.     lsl.w    #5,d0
  112.     adda.w    d0,a0
  113.     lsl.w    #2,d0
  114.     adda.w    d0,a0    ; add 160*y to cscreen and put in a0
  115.     move.w    4(sp),d0    ; get x coordinate
  116.     bge    xposi    ; x is positive at least
  117.     cmp.w    #-16,d0    ; if negative is it offscreen entirely?
  118.     bls    clipout    
  119.     bra     left_edge 
  120. xposi
  121.     cmp.w    #320,d0    ; is it offscreen to right?
  122.     bge    clipout
  123.     cmp.w    #320-16,d0 ; partially right clipped?
  124.     bls    add_xadd
  125.     bra    right_edge    
  126. add_xadd
  127.     and.w    #$fff0,d0    
  128.     lsr.w    #1,d0
  129.     adda.w    d0,a0    ; point a0 to the right word even ... 
  130.     move.l    #ds_cs,a1
  131.     move.l    0(a1,d2.w),a1    ; get rest of routine for this color
  132.     jmp    (a1)
  133. clipout    rts
  134.  
  135.  
  136. left_edge     adda.w    #2,a2    ; skip left part of brush
  137.     bra do_edge
  138. right_edge  
  139.     adda.w    #160-8,a0 ; we're in the last word of this line
  140. do_edge
  141.     move.l    #ss_cs,a1
  142.     move.l    0(a1,d2.w),a1    ; get clipped routine for this color
  143.     jmp    (a1)
  144.  
  145.  
  146. ;    start of repetitive code, bunch of routines, one for each color.
  147. ;    dsc? moves a full brush to screen,  ssc? moves either left or
  148. ;    right half of brush to screen (seems useless but it happens when
  149. ;    you're on the edge ... another complexity added by clipping
  150. ;
  151. dsc0:    
  152.     move.w    (a2)+,d0
  153.     not.w    d0
  154.     and.w    d0,(a0)+
  155.     and.w    d0,(a0)+
  156.     and.w    d0,(a0)+
  157.     and.w    d0,(a0)+
  158.     move.w    (a2)+,d0
  159.     not.w    d0
  160.     and.w    d0,(a0)+
  161.     and.w    d0,(a0)+
  162.     and.w    d0,(a0)+
  163.     and.w    d0,(a0)+
  164.     adda    #160-16,a0    ; go to next row of dest
  165.     dbra    d1,dsc0
  166.     rts
  167.  
  168. dsc1: 
  169.     move.w    (a2)+,d0
  170.     or.w    d0,(a0)+
  171.     not.w    d0
  172.     and.w    d0,(a0)+
  173.     and.w    d0,(a0)+
  174.     and.w    d0,(a0)+
  175.     move.w    (a2)+,d0
  176.     or.w    d0,(a0)+
  177.     not.w    d0
  178.     and.w    d0,(a0)+
  179.     and.w    d0,(a0)+
  180.     and.w    d0,(a0)+
  181.     adda    #160-16,a0    ; go to next row of dest
  182.     dbra    d1,dsc1
  183.     rts
  184.  
  185. dsc2: 
  186.     move.w    (a2)+,d0
  187.     or.w    d0,2(a0)
  188.     not.w    d0
  189.     and.w    d0,0(a0)
  190.     and.w    d0,4(a0)
  191.     and.w    d0,6(a0)
  192.     move.w    (a2)+,d0
  193.     or.w    d0,8+2(a0)
  194.     not.w    d0
  195.     and.w    d0,8+0(a0)
  196.     and.w    d0,8+4(a0)
  197.     and.w    d0,8+6(a0)
  198.     adda.w    #160,a0    ; go to next row of dest
  199.     dbra    d1,dsc2
  200.     rts
  201.  
  202. dsc3:
  203.     move.w    (a2)+,d0
  204.     or.w    d0,(a0)+
  205.     or.w    d0,(a0)+
  206.     not.w    d0
  207.     and.w    d0,(a0)+
  208.     and.w    d0,(a0)+
  209.     move.w    (a2)+,d0
  210.     or.w    d0,(a0)+
  211.     or.w    d0,(a0)+
  212.     not.w    d0
  213.     and.w    d0,(a0)+
  214.     and.w    d0,(a0)+
  215.     adda.w    #160-16,a0    ; go to next row of dest
  216.     dbra    d1,dsc3
  217.     rts
  218.  
  219. dsc4:
  220.     move.w    (a2)+,d0
  221.     or.w    d0,4(a0)
  222.     not.w    d0
  223.     and.w    d0,(a0)+
  224.     and.w    d0,(a0)
  225.     adda.w    #4,a0
  226.     and.w    d0,(a0)+
  227.     move.w    (a2)+,d0
  228.     or.w    d0,4(a0)
  229.     not.w    d0
  230.     and.w    d0,(a0)+
  231.     and.w    d0,(a0)
  232.     addq    #4,a0
  233.     and.w    d0,(a0)+
  234.     adda.w    #160-16,a0    ; go to next row of dest
  235.     dbra    d1,dsc4
  236.     rts
  237.  
  238. dsc5:
  239.     move.w    (a2)+,d0
  240.     or.w    d0,0(a0)
  241.     or.w    d0,4(a0)
  242.     not.w    d0
  243.     and.w    d0,2(a0)
  244.     and.w    d0,6(a0)
  245.     move.w    (a2)+,d0
  246.     or.w    d0,8+0(a0)
  247.     or.w    d0,8+4(a0)
  248.     not.w    d0
  249.     and.w    d0,8+2(a0)
  250.     and.w    d0,8+6(a0)
  251.     adda.w    #160,a0    ; go to next row of dest
  252.     dbra    d1,dsc5
  253.     rts
  254.  
  255. dsc6:
  256.     move.w    (a2)+,d0
  257.     or.w    d0,2(a0)
  258.     or.w    d0,4(a0)
  259.     not.w    d0
  260.     and.w    d0,0(a0)
  261.     and.w    d0,6(a0)
  262.     move.w    (a2)+,d0
  263.     or.w    d0,8+2(a0)
  264.     or.w    d0,8+4(a0)
  265.     not.w    d0
  266.     and.w    d0,8+0(a0)
  267.     and.w    d0,8+6(a0)
  268.     adda.w    #160,a0    ; go to next row of dest
  269.     dbra    d1,dsc6
  270.     rts
  271.  
  272. dsc7:
  273.     move.w    (a2)+,d0
  274.     or.w    d0,(a0)+
  275.     or.w    d0,(a0)+
  276.     or.w    d0,(a0)+
  277.     not.w    d0
  278.     and.w    d0,(a0)+
  279.     move.w    (a2)+,d0
  280.     or.w    d0,(a0)+
  281.     or.w    d0,(a0)+
  282.     or.w    d0,(a0)+
  283.     not.w    d0
  284.     and.w    d0,(a0)+
  285.     adda.w    #160-16,a0    ; go to next row of dest
  286.     dbra    d1,dsc7
  287.     rts
  288.  
  289. dsc8:    
  290.     move.w    (a2)+,d0
  291.     not.w    d0
  292.     and.w    d0,(a0)+
  293.     and.w    d0,(a0)+
  294.     and.w    d0,(a0)+
  295.     not.w    d0
  296.     or.w    d0,(a0)+
  297.     move.w    (a2)+,d0
  298.     not.w    d0
  299.     and.w    d0,(a0)+
  300.     and.w    d0,(a0)+
  301.     and.w    d0,(a0)+
  302.     not.w    d0
  303.     or.w    d0,(a0)+
  304.     adda.w    #160-16,a0    ; go to next row of dest
  305.     dbra    d1,dsc8
  306.     rts
  307.  
  308. dsc9: 
  309.     move.w    (a2)+,d0
  310.     or.w    d0,(a0)+
  311.     or.w    d0,4(a0)
  312.     not.w    d0
  313.     and.w    d0,(a0)+
  314.     and.w    d0,(a0)
  315.     adda.w    #4,a0
  316.     move.w    (a2)+,d0
  317.     or.w    d0,(a0)+
  318.     or.w    d0,4(a0)
  319.     not.w    d0
  320.     and.w    d0,(a0)+
  321.     and.w    d0,(a0)
  322.     adda.w    #160+4-16,a0    ; go to next row of dest
  323.     dbra    d1,dsc9
  324.     rts
  325.  
  326. dsca: 
  327.     move.w    (a2)+,d0
  328.     or.w    d0,2(a0)
  329.     or.w    d0,6(a0)
  330.     not.w    d0
  331.     and.w    d0,0(a0)
  332.     and.w    d0,4(a0)
  333.     move.w    (a2)+,d0
  334.     or.w    d0,8+2(a0)
  335.     or.w    d0,8+6(a0)
  336.     not.w    d0
  337.     and.w    d0,8+0(a0)
  338.     and.w    d0,8+4(a0)
  339.     adda.w    #160,a0    ; go to next row of dest
  340.     dbra    d1,dsca
  341.     rts
  342.  
  343. dscb:
  344.     move.w    (a2)+,d0
  345.     or.w    d0,(a0)+
  346.     or.w    d0,(a0)+
  347.     or.w    d0,2(a0)
  348.     not.w    d0
  349.     and.w    d0,(a0)
  350.     adda.w    #4,a0
  351.     move.w    (a2)+,d0
  352.     or.w    d0,(a0)+
  353.     or.w    d0,(a0)+
  354.     or.w    d0,2(a0)
  355.     not.w    d0
  356.     and.w    d0,(a0)
  357.     adda.w    #160-16+4,a0    ; go to next row of dest
  358.     dbra    d1,dscb
  359.     rts
  360.  
  361. dscc:
  362.     move.w    (a2)+,d0
  363.     not.w    d0
  364.     and.w    d0,(a0)+
  365.     and.w    d0,(a0)+
  366.     not.w    d0
  367.     or.w    d0,(a0)+
  368.     or.w    d0,(a0)+
  369.     move.w    (a2)+,d0
  370.     not.w    d0
  371.     and.w    d0,(a0)+
  372.     and.w    d0,(a0)+
  373.     not.w    d0
  374.     or.w    d0,(a0)+
  375.     or.w    d0,(a0)+
  376.     adda.w    #160-16,a0    ; go to next row of dest
  377.     dbra    d1,dscc
  378.     rts
  379.  
  380. dscd:
  381.     move.w    (a2)+,d0
  382.     or.w    d0,0(a0)
  383.     or.w    d0,4(a0)
  384.     or.w    d0,6(a0)
  385.     not.w    d0
  386.     and.w    d0,2(a0)
  387.     move.w    (a2)+,d0
  388.     or.w    d0,8+0(a0)
  389.     or.w    d0,8+4(a0)
  390.     or.w    d0,8+6(a0)
  391.     not.w    d0
  392.     and.w    d0,8+2(a0)
  393.     adda.w    #160,a0    ; go to next row of dest
  394.     dbra    d1,dscd
  395.     rts
  396.  
  397. dsce:
  398.     move.w    (a2)+,d0
  399.     or.w    d0,2(a0)
  400.     or.w    d0,4(a0)
  401.     or.w    d0,6(a0)
  402.     not.w    d0
  403.     and.w    d0,0(a0)
  404.     move.w    (a2)+,d0
  405.     or.w    d0,8+2(a0)
  406.     or.w    d0,8+4(a0)
  407.     or.w    d0,8+6(a0)
  408.     not.w    d0
  409.     and.w    d0,8+0(a0)
  410.     adda.w    #160,a0    ; go to next row of dest
  411.     dbra    d1,dsce
  412.     rts
  413.  
  414. dscf:
  415.     move.w    (a2)+,d0
  416.     or.w    d0,(a0)+
  417.     or.w    d0,(a0)+
  418.     or.w    d0,(a0)+
  419.     or.w    d0,(a0)+
  420.     move.w    (a2)+,d0
  421.     or.w    d0,(a0)+
  422.     or.w    d0,(a0)+
  423.     or.w    d0,(a0)+
  424.     or.w    d0,(a0)+
  425.     adda.w    #160-16,a0    ; go to next row of dest
  426.     dbra    d1,dscf
  427.     rts
  428.  
  429. ssc0:    
  430.     move.w    (a2),d0
  431.     not.w    d0
  432.     and.w    d0,(a0)+
  433.     and.w    d0,(a0)+
  434.     and.w    d0,(a0)+
  435.     and.w    d0,(a0)+
  436.     adda    #160-8,a0    ; go to next row of dest
  437.     adda    #4,a2
  438.     dbra    d1,ssc0
  439.     rts
  440.  
  441. ssc1: 
  442.     move.w    (a2),d0
  443.     or.w    d0,(a0)+
  444.     not.w    d0
  445.     and.w    d0,(a0)+
  446.     and.w    d0,(a0)+
  447.     and.w    d0,(a0)+
  448.     adda    #160-8,a0    ; go to next row of dest
  449.     adda    #4,a2
  450.     dbra    d1,ssc1
  451.     rts
  452.  
  453. ssc2: 
  454.     move.w    (a2),d0
  455.     or.w    d0,2(a0)
  456.     not.w    d0
  457.     and.w    d0,0(a0)
  458.     and.w    d0,4(a0)
  459.     and.w    d0,6(a0)
  460.     adda.w    #160,a0    ; go to next row of dest
  461.     adda    #4,a2
  462.     dbra    d1,ssc2
  463.     rts
  464.  
  465. ssc3:
  466.     move.w    (a2),d0
  467.     or.w    d0,(a0)+
  468.     or.w    d0,(a0)+
  469.     not.w    d0
  470.     and.w    d0,(a0)+
  471.     and.w    d0,(a0)+
  472.     adda.w    #160-8,a0    ; go to next row of dest
  473.     adda    #4,a2
  474.     dbra    d1,ssc3
  475.     rts
  476.  
  477. ssc4:
  478.     move.w    (a2),d0
  479.     or.w    d0,4(a0)
  480.     not.w    d0
  481.     and.w    d0,(a0)+
  482.     and.w    d0,(a0)
  483.     adda.w    #4,a0
  484.     and.w    d0,(a0)+
  485.     adda.w    #160-8,a0    ; go to next row of dest
  486.     adda    #4,a2
  487.     dbra    d1,ssc4
  488.     rts
  489.  
  490. ssc5:
  491.     move.w    (a2),d0
  492.     or.w    d0,0(a0)
  493.     or.w    d0,4(a0)
  494.     not.w    d0
  495.     and.w    d0,2(a0)
  496.     and.w    d0,6(a0)
  497.     adda.w    #160,a0    ; go to next row of dest
  498.     adda    #4,a2
  499.     dbra    d1,ssc5
  500.     rts
  501.  
  502. ssc6:
  503.     move.w    (a2),d0
  504.     or.w    d0,2(a0)
  505.     or.w    d0,4(a0)
  506.     not.w    d0
  507.     and.w    d0,0(a0)
  508.     and.w    d0,6(a0)
  509.     adda.w    #160,a0    ; go to next row of dest
  510.     adda    #4,a2
  511.     dbra    d1,ssc6
  512.     rts
  513.  
  514. ssc7:
  515.     move.w    (a2),d0
  516.     or.w    d0,(a0)+
  517.     or.w    d0,(a0)+
  518.     or.w    d0,(a0)+
  519.     not.w    d0
  520.     and.w    d0,(a0)+
  521.     adda.w    #160-8,a0    ; go to next row of dest
  522.     adda    #4,a2
  523.     dbra    d1,ssc7
  524.     rts
  525.  
  526. ssc8:    
  527.     move.w    (a2),d0
  528.     not.w    d0
  529.     and.w    d0,(a0)+
  530.     and.w    d0,(a0)+
  531.     and.w    d0,(a0)+
  532.     not.w    d0
  533.     or.w    d0,(a0)+
  534.     adda.w    #160-8,a0    ; go to next row of dest
  535.     adda    #4,a2
  536.     dbra    d1,ssc8
  537.     rts
  538.  
  539. ssc9: 
  540.     move.w    (a2),d0
  541.     or.w    d0,(a0)+
  542.     or.w    d0,4(a0)
  543.     not.w    d0
  544.     and.w    d0,(a0)+
  545.     and.w    d0,(a0)
  546.     adda.w    #160+4-8,a0    ; go to next row of dest
  547.     adda    #4,a2
  548.     dbra    d1,ssc9
  549.     rts
  550.  
  551. ssca: 
  552.     move.w    (a2),d0
  553.     or.w    d0,2(a0)
  554.     or.w    d0,6(a0)
  555.     not.w    d0
  556.     and.w    d0,0(a0)
  557.     and.w    d0,4(a0)
  558.     adda.w    #160,a0    ; go to next row of dest
  559.     adda    #4,a2
  560.     dbra    d1,ssca
  561.     rts
  562.  
  563. sscb:
  564.     move.w    (a2),d0
  565.     or.w    d0,(a0)+
  566.     or.w    d0,(a0)+
  567.     or.w    d0,2(a0)
  568.     not.w    d0
  569.     and.w    d0,(a0)
  570.     adda.w    #160-8+4,a0    ; go to next row of dest
  571.     adda    #4,a2
  572.     dbra    d1,sscb
  573.     rts
  574.  
  575. sscc:
  576.     move.w    (a2),d0
  577.     not.w    d0
  578.     and.w    d0,(a0)+
  579.     and.w    d0,(a0)+
  580.     not.w    d0
  581.     or.w    d0,(a0)+
  582.     or.w    d0,(a0)+
  583.     adda.w    #160-8,a0    ; go to next row of dest
  584.     adda    #4,a2
  585.     dbra    d1,sscc
  586.     rts
  587.  
  588. sscd:
  589.     move.w    (a2),d0
  590.     or.w    d0,0(a0)
  591.     or.w    d0,4(a0)
  592.     or.w    d0,6(a0)
  593.     not.w    d0
  594.     and.w    d0,2(a0)
  595.     adda.w    #160,a0    ; go to next row of dest
  596.     adda    #4,a2
  597.     dbra    d1,sscd
  598.     rts
  599.  
  600. ssce:
  601.     move.w    (a2),d0
  602.     or.w    d0,2(a0)
  603.     or.w    d0,4(a0)
  604.     or.w    d0,6(a0)
  605.     not.w    d0
  606.     and.w    d0,0(a0)
  607.     adda.w    #160,a0    ; go to next row of dest
  608.     adda    #4,a2
  609.     dbra    d1,ssce
  610.     rts
  611.  
  612. sscf:
  613.     move.w    (a2),d0
  614.     or.w    d0,(a0)+
  615.     or.w    d0,(a0)+
  616.     or.w    d0,(a0)+
  617.     or.w    d0,(a0)+
  618.     adda.w    #160-8,a0    ; go to next row of dest
  619.     adda    #4,a2
  620.     dbra    d1,sscf
  621.     rts
  622.  
  623.  
  624.     bss    shift_buf,64    ; place to shift one brush
  625.     bss    preshifts,64*16    ; place for 16 shifted copies of brush
  626.  
  627.  
  628.     bss    shift_buf,64    ; place to shift one brush
  629.     bss    preshifts,64*16    ; place for 16 shifted copies of brush
  630.  
  631.     dseg
  632. ds_cs    dc.l     dsc0,dsc1,dsc2,dsc3,dsc4,dsc5,dsc6,dsc7
  633.     dc.l    dsc8,dsc9,dsca,dscb,dscc,dscd,dsce,dscf
  634. ss_cs    dc.l     ssc0,ssc1,ssc2,ssc3,ssc4,ssc5,ssc6,ssc7
  635.     dc.l    ssc8,ssc9,ssca,sscb,sscc,sscd,ssce,sscf
  636.  
  637.